<%-- 
    Document   : viewProfile
    Created on : Mar 8, 2012, 12:10:08 AM
    Author     : 013v
--%>
<%@page import="java.sql.ResultSet"%>
<%@page import="Model.ProductManager"%>
<%@page import="Model.CustomerManager"%>
<%@page import="Model.Customer"%>
<%
    String loginAttempt = request.getParameter("loginAttempt");
    if (loginAttempt != null) {
        boolean isValid = true;

        if (loginAttempt.indexOf("<") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(">") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("\"") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("/") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(":") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf(";") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("=") > -1) {
            isValid = false;
        } else if (loginAttempt.indexOf("|") > -1) {
            isValid = false;
        }

        if (isValid == false) {
            loginAttempt = null;
        }
    }
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/foo.css" type="text/css"/>
        <link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen">	
        <title>Foobar</title>
        <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="js/hoverIntent.js"></script>
        <script type="text/javascript" src="js/superfish.js"></script>
        <script type="text/javascript" src="js/LoginValidation.js"></script>
        <script type="text/javascript" src="js/SearchValidation.js"></script>
        <script type="text/javascript">

            // initialise plugins
            jQuery(function(){
                jQuery('ul.sf-menu').superfish();
            });
           
            function checkAuth(){
              if(<%=request.getParameter("loginAttempt")%>==false && isValid){
                 document.write('<span class="errLog">Authentication failed.</span>');
               }
               else if (<%=request.getParameter("loginMax")%>==true && isValidMax){
                   document.write('<span class="errLog">You have reached your maximum login attempts. Please try again later.</span>');
               }
         }
        </script>
    </head>
    <body class="bg">
        <br/>
        <div class="hmenu">
            <% if (request.getSession(true).getAttribute("username") == null) {%>
            <p style="font-size: 12px; margin-top: -15px; float: right;">If you're not yet a member, sign up <a href="signUp.jsp" class="lin">here!</a> </p>   
            <% }%>
            <img src="images/head.png" style="float: left; margin-left:20px;"/>
            <div class="log">
                <% if (request.getSession(true).getAttribute("username") != null) {%>
                <span>Hello <%=session.getAttribute("username")%>!</span><br>
                <span style="font-weight: normal; font-size: 10px;">You have <%=session.getAttribute("numCart")%> items in your cart.</span>
                <div id="nav">
                    <ul class="top">
                        <li><a href="viewCart.jsp">View Cart</a></li>
                        <li><a href="checkOut.jsp">Checkout</a></li>
                        <li><a href="viewProfile.jsp">Account Details</a></li>
                        <li><a href="LogoutServlet">Log out</a></li>
                    </ul>
                </div>
                <% } else {%>
                <span style="font-weight: bold;">Log in</span>
                <form method="post" action="LoginServlet">
                    <label>Username:</label><input type="text" id="username" name="username"/><br/>
                    <label>Password:</label><input type="password" id="password" name="password"/><br/>
                    <input type="submit" onClick="return LoginValidation()" value="Log in" name="submit"/>
                    <label class="errLog" id="err"></label>
                </form>
                <% }%>
            </div>
            <ul class="sf-menu">
                <li class="current">
                    <a href="index.jsp">Home</a>
                </li>
                <li>
                    <a href="#">Products</a>
                    <ul>
                                        <%
                ResultSet rs = new ProductManager().getProductTypes();
                while(rs.next()){
                %>
                        <li>
                            <a href="products.jsp?prd=<%=rs.getInt("ProductTypeID")%>"><%=rs.getString("ProductType")%></a>
                        </li>
                <%}%>
                    </ul>
                </li>
                <li>
                    <a href="#">Stores</a>
                </li>
                <li>
                    <a href="#">Contact Us</a>
                </li>
                <li>
                    <form action="results.jsp">
                            <input type="text" name="search" placeholder="Enter your search"/>
                            <button type="submit" onClick="return SearchValidation(this.form);">Go</button>
                    </form>
                </li>
            </ul>
        </div>
        <div class="content">
            <%

                Customer cst = new CustomerManager().getCustomerDetails(session.getAttribute("username").toString());

            %>
            <span style="font-size:large; font-weight: bold">Account Settings</span>&nbsp;&nbsp;&nbsp;<a href="editProf.jsp" class="lin">Edit</a><br/><br/>
            <label class="data">Username: </label><span class="info">&nbsp;<%=cst.getNewUser().getUsername()%></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="changePassword.jsp" class="lin">Change Password</a><br/>
            <label class="data">Name: </label><span class="info">&nbsp;<%=cst.getNewUser().getFirstName()%>&nbsp;<%=cst.getNewUser().getMiddleInitial()%>.&nbsp;<%=cst.getNewUser().getLastName()%></span><br/>
            <label class="data">Email address: </label><span class="info">&nbsp;<%=cst.getNewUser().getEmail()%></span><br/>
            <br><label class="data">Credit card information</label><br>
            <label class="data">Billing address: </label>
            <span class="info">&nbsp;<%=cst.getNewCred().getCCBHouseNum()%>
                &nbsp;<%=cst.getNewCred().getCCBStreet()%>
                &nbsp;<%=cst.getNewCred().getCCBSubdivision()%>,
                &nbsp;<%=cst.getNewCred().getCCBCity()%>,
                &nbsp;<%=cst.getNewCred().getCCBZip()%>,
                &nbsp;<%=cst.getNewCred().getCCBCountry()%>
            </span><br/>
            <br><label class="data">Shipping information</label><br>
            <label class="data">Delivery address: </label>
            <span class="info">&nbsp;<%=cst.getNewDeliv().getDAHouseNum()%>
                &nbsp;<%=cst.getNewDeliv().getDAStreet()%>
                &nbsp;<%=cst.getNewDeliv().getDASubdivision()%>,
                &nbsp;<%=cst.getNewDeliv().getDACity()%>,
                &nbsp;<%=cst.getNewDeliv().getDAZip()%>,
                &nbsp;<%=cst.getNewDeliv().getDACountry()%>
            </span><br/>
            <br/>
        </div>
    </body>
</html>
